home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!news
- From: jlilley@ix.netcom.com (John Lilley)
- Newsgroups: comp.lang.c++
- Subject: Re: scope of operators
- Date: 29 Mar 1996 16:25:10 GMT
- Organization: Netcom
- Message-ID: <4jh2t6$scq@dfw-ixnews6.ix.netcom.com>
- References: <4jd23q$jp4@vixen.cso.uiuc.edu>
- NNTP-Posting-Host: den-co11-03.ix.netcom.com
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=US-ASCII
- X-NETCOM-Date: Fri Mar 29 10:25:10 AM CST 1996
- X-Newsreader: WinVN 0.99.7
-
- In article <4jd23q$jp4@vixen.cso.uiuc.edu>, wemccaug@prairienet.org says...
- >
- >
- > It is my understanding that if I declare 'f' to be a
- > friend of a base class, it should apply to objects of
- > the derived class with impunity. For instance, if 'f'
- > is supposed to take one argument that is an object of
- > the base class and I pass an object of the derived
- > class instead, should I not expect conformity? I am not
- > doing anything in the derived class object apart from
- > what it has inherited from the base class at all.
-
- The following compiles fine for BC++4.5:
-
- class A {
- friend void f(A*);
- private:
- int x;
- };
-
- class B: public A
- {
- };
-
- void f(A* a)
- {
- a->x = 1;
- }
-
- void g()
- {
- A a;
- B b;
-
- f(&a);
- f(&b);
- }
-
-
- You must make sure that A is a *public* base of B, else you cannot
- implicitly case *B to *A.
-
- john lilley
-
-